<template>
	<view class="content">
		<view class="top_content app_content_color" id="search">
			<view class="search_content app_background_color">
				<input class="search_input app_title_color" placeholder="输入搜索内容" confirm-type="search" @input="searchInput"
					@confirm="searchButtonTap" :value="keyword" />
				<view class="search_button_content" @tap="searchButtonTap">
					<image class="search_button_icon" src="../../static/search_icon.png"></image>
				</view>
			</view>
			
			<view class="segment_content app_background_color" v-if="selectIndex == 0">
				<view class="segment_cell_content app_content_color app_title_color">热门帖子</view>
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(1)">最新发表</view>
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(2)">最新回复</view>
			</view>
			<view class="segment_content app_background_color" v-if="selectIndex == 1">
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(0)">热门帖子</view>
				<view class="segment_cell_content app_content_color app_title_color">最新发表</view>
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(2)">最新回复</view>
			</view>
			<view class="segment_content app_background_color" v-if="selectIndex == 2">
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(0)">热门帖子</view>
				<view class="segment_cell_content app_title_color segment_cell_unselect_content app_background_color" @tap="selectIndexTap(1)">最新发表</view>
				<view class="segment_cell_content app_content_color app_title_color">最新回复</view>
			</view>
		</view>
		<swiper scroll-x :style="'height: '+scrollHeight+'px;'" :current="selectIndex" @change="swiperChange">
			<swiper-item>
				<post-list-view :showSubscription="true" :moduleId="2" url="portal/newslist" :height="scrollHeight"></post-list-view>
			</swiper-item>
			<swiper-item>
				<post-list-view sortby="new" url="forum/topiclist" :height="scrollHeight"></post-list-view>
			</swiper-item>
			<swiper-item>
				<post-list-view sortby="all" url="forum/topiclist" :height="scrollHeight"></post-list-view>
			</swiper-item>
		</swiper>
		
		<view class="forum_write_button app-card" @tap="writeForumTap">
			<image class="forum_write_image" mode="aspectFit" src="../../static/forun_write_img.png"></image>
			<view>写帖子</view>
		</view>
	</view>
</template>

<style lang="scss">
	.content {
		display: flex;
		width: 100%;
		flex-direction: column;
	}

	.top_content {
		display: flex;
		width: 100%;
		flex-direction: column;
	}

	.search_content {
		display: flex;
		height: 100upx;
		margin-left: 30upx;
		margin-right: 30upx;
		flex-direction: row;
		border-radius: 8upx;
		margin-top: 50upx;
		margin-bottom: 30upx;
	}

	.search_input {
		height: 100%;
		font-size: 30upx;
		flex-grow: 1;
		margin-left: 20upx;
		margin-right: 20upx;
	}

	.search_button_content {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #aaaaaa;
		height: 100%;
		width: 120upx;
		border-top-right-radius: 8upx;
		border-bottom-right-radius: 8upx;
	}

	.search_button_icon {
		width: 60upx;
		height: 60upx;
	}
	
	.segment_content {
		display: flex;
		height: 60upx;
		margin-left: 30upx;
		margin-right: 30upx;
		flex-direction: row;
		border-radius: 8upx;
		margin-top: 20upx;
		margin-bottom: 30upx;
		padding: 2upx;
	}
	.segment_cell_content {
		display: flex;
		justify-content: center;
		font-size: 28upx;
		justify-content: center;
		align-items: center;
		border-radius: 8upx;
		flex-grow: 1;
	}
	
	.segment_cell_unselect_content {
		font-size: 24upx;
		color: #aaaaaa;
	}

	.forum_top_cell_content {
		display: flex;
		width: 100%;
		flex-direction: row;
		align-items: center;
		background-color: $uni-global-content-color;
		margin-top: 1upx;
		padding-top: 30upx;
		padding-bottom: 30upx;
	}

	.forum_top_cell_icon {
		margin-left: 30upx;
		width: 80upx;
		height: 80upx;
	}

	.forum_top_cell_info_content {
		display: flex;
		flex-direction: column;
		color: #fff;
		flex-grow: 1;
		margin-left: 20upx;
	}

	.forum_top_cell_info_title {
		font-size: 35upx;
	}

	.forum_top_cell_info_subtitle {
		font-size: 25upx;
		margin-top: 10upx;
	}

	.forum_top_cell_arrow_icon {
		margin-right: 30upx;
		margin-left: 20upx;
		width: 30upx;
		height: 30upx;
	}
	
	.forum_write_button{
		display: flex;
		border-radius: 50%;
		width: 120upx;
		height: 120upx;
		background-color: $uni-global-green-color;
		justify-content: center;
		align-items: center;
		position: fixed;
		right: 50upx;
		bottom: 50upx;
		color: #fff;
		font-size: 23upx;
		flex-direction: column;
	}
	
	.forum_write_image{
		width: 40upx;
		height: 40upx;
		margin-bottom: 5upx;
	}
</style>


<script>
	import util from '../../utils/util.js'
	import http from "../../utils/http.js"
	export default {
		data() {
			return {
				items: [],
				keyword: "",
				isSubscription: true,
				scrollHeight: 0,
				selectIndex:0
			}
		},
		onLoad() {
			this.getHeight()
		},
		methods: {
			getHeight() {
				let that = this
				uni.getSystemInfo({
					success: (res) => {
						console.log(res)
						// 获取屏幕高度
						let windowHeight = res.windowHeight;
						const query = uni.createSelectorQuery().in(that);
						query.select('#search').boundingClientRect(data => {
							console.log(data)
							that.scrollHeight = windowHeight - data.bottom;
						}).exec();
					},
				});
			},
			selectIndexTap(index){
				this.selectIndex = index
			},
			swiperChange(e){
				this.selectIndex = e.detail.current
			},
			searchInput(e) {
				this.keyword = e.detail.value;
			},
			searchButtonTap() {
				if (this.keyword.length == 0) {
					return;
				}
				if(getApp().globalData.user == null){
					uni.navigateTo({
						url:"../login/login"
					})
					return
				}
				uni.navigateTo({
					url: "../forum-search-post-list/forum-search-post-list?keyword=" + this.keyword
				})
			},
			writeForumTap(){
				if(getApp().globalData.user == null){
					uni.navigateTo({
						url:"../login/login"
					})
					return
				}
				uni.navigateTo({
					url:"../select-board/select-board"
				})
			}
		}
	}
</script>
